﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using System.Reflection;
using System.ComponentModel;
using System.Globalization;
using System.Windows;

namespace DeviceMgtModule.Converter
{
    #region String2BooleanConverter

    public class String2BooleanConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null && value is string)
            {
                if (value.ToString().Equals("1"))
                {
                    return true;
                }
            }

            return false;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool)
            {
                if ((bool)value)
                    return "1";
            }
            return "0";
        }
    }

    #endregion

    #region String2StringConverter

    public class String2StringConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            if (value != null && parameter is string)
            {
                switch (parameter as string)
                {
                    case "DriverType":
                        switch (value as string)
                        {
                            case "DH":
                                return "大华";
                            case "HK":
                                return "海康";

                            default:
                                return "其它";
                        }
                    case "Status":
                        switch (value as string)
                        {
                            case "1":
                                return "启用";
                            case "0":
                                return "未启用";

                            default:
                                return value.ToString();
                        }


                    default:
                        return value.ToString();
                }
            }

            if (value != null)
                return value.ToString();
            else
                return string.Empty;
        }

        public object ConvertBack(object value, Type targetType, object parameter,
            System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }

    #endregion
}
